/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: H_tao_X
 * Date: 2022-11-16
 * Time: 16:04
 */

import com.beans.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 这是一个启动类
 */
public class App {
    public static void main(String[] args) {
        // 1. 先获取上下问
        ApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");
        // 2. 获取 Bean，通过 Bean和 类型
        UserController userController = context.getBean("userController",UserController.class);
        Component component = context.getBean("component", Component.class);
        Configuration configuration = context.getBean("configuration", Configuration.class);
        Repository repository = context.getBean("repository", Repository.class);
        Service service = context.getBean("service", Service.class);
        // 使用@Bean 存储 Bean ，要配合 五大类注解一起使用
//        User user = context.getBean(User.class);
        // 注意 @Bean 注解这里获取 Bean 必须使用 方法名
        User user = context.getBean("user1",User.class);
        // 3. 使用 Bean
        userController.sayHi();
        component.sayHi();
        configuration.sayHi();
        repository.sayHi();
        service.sayHi();
        System.out.println(user);
    }
}
